import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:yinshui_caiying/services/user_services.dart';
import 'package:yinshui_caiying/utils/colors.dart';
import 'package:yinshui_caiying/utils/screen.dart';
import 'package:popover/popover.dart';

class BackTitleBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final Size preferredSize;
  final Widget? action;
  final bool? hasback;
  BackTitleBar({required this.title, this.action, this.hasback = true})
      : preferredSize = Size.fromHeight(223.h);
  UserService userService = Get.find();
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.fromLTRB(56.w, 120.w, 56.w, 55.w),
      child: Stack(
        children: [
          Align(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    hasback == true
                        ? Container(
                            width: 28.w,
                            height: 48.w,
                            margin: EdgeInsets.only(right: 46.w),
                            child: InkWell(
                              onTap: () {
                                Get.back();
                              },
                              child: Image(
                                image: AssetImage(
                                    'assets/images/appbar/icon-arrow-left.png'),
                                fit: BoxFit.fill,
                              ),
                            ),
                          )
                        : Container(),
                    Container(
                      width: 57.w,
                      height: 57.w,
                      child: InkWell(
                        onTap: () {
                          SmartDialog.show(
                              alignmentTemp: Alignment.topCenter,
                              maskColorTemp: Colors.transparent,
                              widget: Container(
                                padding: EdgeInsets.only(
                                    top: 120.h, left: 46.w, right: 46.w),
                                width: 1.sw,
                                height: 223.h,
                                color: MyColors.main,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(
                                      '${'用户名：' + userService.userinfo.value.name}',
                                      style: TextStyle(
                                          color: Colors.white, fontSize: 46.sp),
                                    ),
                                    InkWell(
                                      onTap: () {
                                        userService.loginOut();
                                      },
                                      child: Text(
                                        '注销',
                                        style: TextStyle(
                                            color: Colors.red, fontSize: 46.sp),
                                      ),
                                    )
                                  ],
                                ),
                              ));
                        },
                        child: Image(
                          image:
                              AssetImage('assets/images/appbar/icon-user.png'),
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                  ],
                ),
                action != null ? action! : Container()
              ],
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              title,
              style: TextStyle(color: Colors.white, fontSize: 50.sp),
            ),
          ),
        ],
      ),
      decoration: BoxDecoration(color: Color.fromRGBO(11, 193, 173, 1)),
    );
  }
}
